#!/usr/bin/python3
#coding:utf-8
__author__ = 'merci'
l = []
logs = {}
with open('sulao.cn-access.log', 'r', encoding='utf-8') as f:
    while True:
        line = f.readline()
        line = line.strip('\n')
        rows = line.split(' ')
        #添加每行数据到列表
        l.append(rows)
        if not line:
            break
#将列表第一列添加到字典并判断包含在字典内则值+1，否则值设置1
for x in l:
    if x[0] in logs:
        logs[x[0]] += 1
    else:
        logs[x[0]] = 1
#使用zip将字典键和值打包成元祖列表
f = zip(logs.values(), logs.keys())
#reverse参数用来排序，true倒序，false倒序
r = sorted(f,reverse=True)
#循环打印前10的元祖
for p in r[:10]:
    print(p)